<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>公告发布</title>
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<style>
    body {
        background-color: #ffffff;
    }
</style>
<body>
<div class="layuimini-main">
    <form class="layui-form layui-form-pane" style="margin-left: 50px">
        <div class="layui-form-item" style="width: 60%;">
            <label class="layui-form-label required" >公告标题</label>
            <div class="layui-input-block">
                <input type="text" id="noticetitle" name="noticetitle" lay-verify="required" lay-reqtext="请填写公告标题" placeholder="填写公告标题" class="layui-input"/>
            </div>
        </div>
        <div class="layui-form-item layui-form-text" style="width: 60%;">
            <label class="layui-form-label required">公告内容</label>
            <div class="layui-input-block">
                <textarea id="noticeContent" name="noticeContent"  class="layui-textarea" style="height: 400px" lay-verify="required" lay-reqtext="请填写公告内容">

                </textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认添加</button>
        </div>
    </form>
</div>
<script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    layui.use(['layer','form','element'], function () {
        var layer=layui.layer,
            form=layui.form,
            $=layui.$,
            element=layui.element;
        form.on('submit(saveBtn)',function(data){
            console.log(data.field)
            var data=$.parseJSON(JSON.stringify(data.field))
            $.ajax({
                url:'/notice/addNotice',
                dataType:'json',
                data:{'noticetitle':data.noticetitle,'noticecontent':data.noticeContent},
                method:'post',
                async:true,
                success:function(data){
                    if(data){
                        layer.msg("发布公告成功，请到首页查看最新公告",
                            {
                              icon:1,
                              time:500
                            },
                            function (){//清空消息
                            $("#noticetitle").val(null);
                            $("#noticeContent").val(null);
                        })
                    }else{
                        layer.msg('发布公告失败，请联系超级管理员舒先生',{
                            icon:2,
                            time:500
                        })
                    }
                }
            })
            return false;
        })
    });
</script>
</body>
</html>